<template>
	<view class="px24 page pt1 pb125 ">
		<!-- 导航栏 -->
		<!-- <uni-nav-bar backgroundColor="#F7F7F7" color="#222" left-icon="left"  leftWidth="50rpx" :border="false"
			@clickLeft="back" statusBar :title="title" fixed></uni-nav-bar> -->
		<!-- 导航栏 -->

		<view class="bgWhite br20 py40 px30 mt20 " v-for="item in list" :key="item.id">
			<view class="flex flex-between align-center col8">
				<text>{{$u.timeFormat(item.create_time, 'yyyy-mm-dd hh:MM')}}</text>

				<image @click="editCilck(item)" style="width:27rpx; height:30rpx;" src="/static/addRecord/edit.png"
					mode="">
				</image>
			</view>
			<view class="mt20 col555">
				日期：
				<text class="col2 fontw500">{{$u.timeFormat(item.time, 'yyyy-mm-dd')}}</text>
			</view>
			<view class="mt20 col555" >
				<text v-if="form.type==1">肥料名称：</text>
				<text v-if="form.type==2">农药名称：</text>
				<text class="col2 fontw500">{{item.name}}</text>
			</view>
			<view class="mt20 col555">
				<text v-if="form.type==1">销售单位：</text>
				<text v-if="form.type==2">销售单位：</text>
				<text class="col2 fontw500">{{item.work}}</text>
			</view>
		</view>
		<u-loadmore class="mt50" iconSize="14" :height="50" font-size="14" :status="status" :loading-text="loadingText"
			:loadmore-text="loadmoreText" :nomore-text="nomoreText" />
		<view @click="addRecord" class="flex mt94 flex-center align-center colf br83"
			style="background: #1F9A64;height: 90rpx; position: fixed; bottom:20rpx; left:20rpx; right:20rpx;">
			<text class="ml20 font32">添加记录</text>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	export default {
		data() {
			return {
				list: [],
				form: {
					page: 1,
					limit: 10,
					type: ''
				},
				status: 'loadmore',
				loadingText: '努力加载中',
				loadmoreText: '轻轻上拉',
				nomoreText: '没有更多了',
			}
		},

		computed: {
			...mapState({
				userInfo: (state) => state.identity.userInfo
			})
		},

		onLoad(options) {
			this.form.type = options.type
			// this.getList()
			uni.setNavigationBarTitle({
				title: options.title
			});

		},
		onShow() {
			this.page=1
			this.list = []
			this.getList()
		},
		onReachBottom(){
			console.log(this.list.length,'ppppppppp')
			if(this.status == "nomore" || this.list.length<6){
				return 
			}
			this.form.page++
			this.getList()
		},
		methods: {
			getList() {
				this.$http({
					url: "/Data/stock_log_list",
					data: {
						...this.form
					},

				}).then(res => {
					this.list.push(...res.data.list)
					if(res.data.list.length<this.form.limit){
						this.status = 'nomore'
						
					}else{
						this.status = 'loadmoer'
					}
				})

			},
			addRecord() {
				 if(this.form.type == 1){
					uni.navigateTo({
						url: `/productPage/pages/feiliaoBuy/feiliaoBuy`
					})
				}else if(this.form.type == 2){
					uni.navigateTo({
						url: `/productPage/pages/nongyaoBuy/nongyaoBuy`
					})
				}
			},
			editCilck(item) {
				 if(this.form.type == 2){
					uni.navigateTo({
						url: `/productPage/pages/nongyaoBuy/nongyaoBuy?id=${item.id}`
					})
				}else if(this.form.type == 1){
					uni.navigateTo({
						url: `/productPage/pages/feiliaoBuy/feiliaoBuy?id=${item.id}`
					})
				}

			},
			back() {
				uni.navigateBack({})
			}
		}
	}
</script>

<style lang="scss" scoped>
	/deep/ .uni-navbar__header-container-inner {
		justify-content: left !important;
	}

	/deep/ .uni-nav-bar-text {
		font-size: 36rpx !important;
	}
</style>